<template>
  <div>
      <v-header title="地址管理" :back="true"></v-header>
       <div v-if="list.length==0">暂无数据</div>

    <van-address-list
      v-model="chosenAddressId"
      :list="list"
      default-tag-text="默认"
      @add="onAdd"
      @edit="onEdit"
      @select="select"
    />
  </div>
</template>

<script>
// import { Toast } from "vant";
import axios from "axios"
export default {
  data() {
    return {
      chosenAddressId: "2",
      list: [
        
      ],
    };
  },
  mounted(){
    axios({
      url:'/api/addresslist',
      method:"get",
      params:{
        uid: JSON.parse(localStorage.getItem("userInfo")).uid,
      },
      headers:{
          authorization:JSON.parse(localStorage.getItem("userInfo")).token
        }
    }).then((res)=>{
      let list = res.data.list ? res.data.list : [];
      
      this.list = list.map((item) => {
        return {
          id: item.id,
          name: item.username,
          tel: item.userphone,
          address: item.location,
          isDefault: item.status == 1 ? true : false,
          areaCode: item.regioncode,
          label: item.label,
          addressDetail: item.useraddress,
        };
      });
    })
  },
  methods: {
    //添加
    onAdd() {
    this.$router.push("/adddizhi")
    },
    //编辑
    onEdit(e) {
      let str = "";
      for (let key in e) {
        str += key + "=" + e[key] + "&";
      }
      //str="id=1&username=123&userphone=23&"
      str = str.slice(0, str.length - 1);
      this.$router.push("/adddizhi?" + str);
    },
    select(e){
      this.$router.push("/qrdd?adddizhi="+e.id)
    }
  },
};
</script>

<style>
</style>